gcapp.set "messageVisible","false"

! line 1 is the tag, 2 is text for those missing text on line 1
! 3 is prompt, 4 is undo message (all required)
Lines "#sm",1,0,@gcapp.scriptMessage
#theTag=#sm[1]
#noName=local(#sm[2])
#inPrmpt=local(#sm[3])
#inUndo=local(#sm[4])
#locOK=local("OK")
#locCancel=local("Cancel")

! get tags (exit if none)
gcapp.get doc,frontDocument
doc.get recRef,"keyRecord"
recRef.findStructures currentTags,#theTag
if @currentTags.count=0
  exit
endif
		
! Get tag text into a list
CreateList theTags
Repeat "#i",0,@currentTags.count-1
  currentTags.#i.get oneTag
  if @oneTag.contents!=""
    theTags.addString @oneTag.contents
  else
    theTags.addString #noName
  endif
EndRepeat

! Pick one
UserChoice "#var",#inPrmpt,theTags,"Delete Tag","false",#locOK,#locCancel
if #var[1]=#locCancel
  exit
endif
#whichOne=#var[3]-1
if #whichOne=0
  exit
endif
doc.beginUndo
! move to the beginning
currentTags.#whichOne.move currentTags.0
doc.endUndo #inUndo
